using Microsoft.Extensions.Configuration;

namespace KernelSyntaxExample.Utils;

public class ProjectEnvironment {
    public const string AoaiEndpoint = nameof(AoaiEndpoint);

    public const string AoaiKey = nameof(AoaiKey);

    public const string AoaiDeploymentName = nameof(AoaiDeploymentName);

    public const string AoaiServiceId = nameof(AoaiServiceId);

    public const string AoaiEmbeddingsEndpoint = nameof(AoaiEmbeddingsEndpoint);

    public const string AoaiEmbeddingsKey = nameof(AoaiEmbeddingsKey);

    public const string AoaiEmbeddingsDeploymentName =
        nameof(AoaiEmbeddingsDeploymentName);

    public const string AoaiEmbeddingsServiceId =
        nameof(AoaiEmbeddingsServiceId);

    private static readonly IConfigurationRoot _configuration =
        new ConfigurationBuilder().AddUserSecrets<ProjectEnvironment>().Build();

    public static string Get(string name) {
        var value = _configuration[name];
        if (!string.IsNullOrEmpty(value)) {
            return value;
        }

        value = Environment.GetEnvironmentVariable(name);
        if (string.IsNullOrEmpty(value)) {
            throw new Exception($"Secret / Env var not set: {name}");
        }

        return value;
    }
}